﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Mtbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.Utility;
using HKEA.CMS.Core.DALFactory;
using System.Linq.Dynamic;
namespace HKEA.CMS.Core.DAL.Mtbl
{
    public class mtblAttendee_StatusDAL:ImtblAttendee_Status
    {
        private HKEA_CMSEntities model;
        private mtblAttendee_Status status;
        public mtblAttendee_StatusDAL()
        {
            model = DataAccess.GetModelInstance();
        }
        public static mtblAttendee_StatusDAL GetInstance()
        {
            return new mtblAttendee_StatusDAL();
        }
        public int InsertENT(mtblAttendee_Status ent)
        {
            ent.CreationDate = DateTime.Now;
            ent.LastModifyDate = DateTime.Now;
            model.mtblAttendee_Status.AddObject(ent);
            return model.SaveChanges();
        }

        public List<mtblAttendee_Status> GetListByENT(mtblAttendee_Status ent, PageParam param, string strPropertyName,string strOrderBy)
        {
            var result = model.mtblAttendee_Status.Where(a => a.Attendee_StatusUID > 0);
            if (ent.Attendee_StatusUID > 0)
                result = result.Where(a => a.Attendee_StatusUID == ent.Attendee_StatusUID);
            if (!string.IsNullOrEmpty(ent.LastModifyBy))
                result = result.Where(a => a.LastModifyBy == ent.LastModifyBy);
            param.Count = result.Count();
            result = result.OrderBy(strPropertyName + " " + strOrderBy).Skip((param.CurrentPage - 1) * param.PageSize).Take(param.PageSize);
            return result.ToList();
        }
        public List<mtblAttendee_Status> GetListByENT(mtblAttendee_Status ent)
        {
            var result = model.mtblAttendee_Status.Where(a => a.Attendee_StatusUID > 0);
            if (ent.Attendee_StatusUID > 0)
                result = result.Where(a => a.Attendee_StatusUID == ent.Attendee_StatusUID);
            if (!string.IsNullOrEmpty(ent.LastModifyBy))
                result = result.Where(a => a.LastModifyBy == ent.LastModifyBy);
            return result.ToList();
        }

        public int GetCountByENT(mtblAttendee_Status ent)
        {
            var result = model.mtblAttendee_Status.Where(a => a.Attendee_StatusUID > 0);
            if (ent.Attendee_StatusUID > 0)
                result = result.Where(a => a.Attendee_StatusUID == ent.Attendee_StatusUID);
            if (!string.IsNullOrEmpty(ent.LastModifyBy))
                result = result.Where(a => a.LastModifyBy == ent.LastModifyBy);
            return result.Count();
        }

        public int UpdateENT(mtblAttendee_Status ent)
        {
            status = model.mtblAttendee_Status.Where(a => a.Attendee_StatusUID == ent.Attendee_StatusUID).FirstOrDefault();
            if (status != null)
            {
                status.Attendee_Status_Chi = ent.Attendee_Status_Chi;
                status.Attendee_Status_Eng = ent.Attendee_Status_Eng;
                status.Deleted = ent.Deleted;
                status.LastModifyBy = ent.LastModifyBy;
                status.LastModifyDate = DateTime.Now;
            }
            return model.SaveChanges();
        }

        public int DeleteENT(mtblAttendee_Status ent)
        {
            status = model.mtblAttendee_Status.Where(a => a.Attendee_StatusUID == ent.Attendee_StatusUID).FirstOrDefault();
            if (status != null)
            {
                model.mtblAttendee_Status.DeleteObject(status);
            }
            return model.SaveChanges();
        }
    }
}
